<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
        <script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
        
        <script type="text/javascript" src="../src/TinyC5-0.7.js"></script>
        <script type="text/javascript" src="../src/TinyC5Utils-0.7.js"></script>
        
        <script>
            $(document).ready(function(){
       
                var currentVersion = 0.7;
                var tinyC5 = new TinyC5();
                
                module( "TinyC5" );
                
                test( "Instance check", function() {
                    ok( "object" == typeof( tinyC5 ), "tinyC5 instance not created." );
                    
                    // Add simple checks for all functions which functionality is hard to check (too lazy for checking them ;-))
                    ok( "function" == typeof( tinyC5.update ), "tinyC5 has no update function." );
                    ok( "function" == typeof( tinyC5.postUpdate ), "tinyC5 has no postUpdate function." );
                    ok( "function" == typeof( tinyC5.start ), "tinyC5 has no start function." );
                    ok( "function" == typeof( tinyC5.resume ), "tinyC5 has no resume function." );
                    ok( "function" == typeof( tinyC5.stop ), "tinyC5 has no stop function." );
                    ok( "function" == typeof( tinyC5.onResize ), "tinyC5 has no onResize function." );
                    ok( "function" == typeof( tinyC5.onMouseMove ), "tinyC5 has no onMouseMove function." );
                    ok( "function" == typeof( tinyC5.onMouseClick ), "tinyC5 has no onMouseClick function." );
                    ok( "function" == typeof( tinyC5.clearPixels ), "tinyC5 has no clearPixels function." );
                });
                
                test( "Properties", function() {
                    ok( "string" == typeof( tinyC5.BROWSER_ENGINE ), "Invalid property BROWSER_ENGINE" );
                    ok( "string" == typeof( tinyC5.FAST_CLICK_EVENT ), "Invalid property FAST_CLICK_EVENT" );
                    ok( "number" == typeof( tinyC5.VERSION ), "Invalid property VERSION" );
                    equal( currentVersion, tinyC5.VERSION , "Incorrect value for VERSION" );                    
                    ok( tinyC5.pixels, "Invalid property: pixels" );
                    ok( "number" == typeof( tinyC5.mouseX ), "Invalid property: mouseX" );
                    ok( "number" == typeof( tinyC5.mouseY ), "Invalid property: mouseY" );
                    ok( "boolean" == typeof( tinyC5.mouseClick ), "Invalid property: mouseClick" );
                    ok( "number" == typeof( tinyC5.WIDTH ), "Invalid property: WIDTH" );
                    ok( "number" == typeof( tinyC5.HEIGHT ), "Invalid property: HEIGHT" );
                    ok( "number" == typeof( tinyC5.VIEW_WIDTH ), "Invalid property: VIEW_WIDTH" );
                    ok( "number" == typeof( tinyC5.VIEW_HEIGHT ), "Invalid property: VIEW_HEIGHT" );                    
                });
                
                test( "Initialization process", function() {
                    
                    ok( "function" == typeof( tinyC5.init ), "tinyC5 has no init function." );
                    
                    var args = {
                        width: 640,
                        height: 480,
                        scale: 2,
                        title: 'TinyC5 Test',
                        container: document.getElementById( 'testOutput' )
                    };
                    
                    tinyC5.init( args );
                    
                    equal( args.width, tinyC5.WIDTH, "Width initialization failed." );
                    equal( args.height, tinyC5.HEIGHT, "Width initialization failed." );
                    equal( args.width * args.scale, tinyC5.VIEW_WIDTH, "Width/scale initialization failed." );
                    equal( args.height * args.scale, tinyC5.VIEW_HEIGHT, "Height/scale initialization failed." );
                    equal( args.title, document.title, "Title initialization failed." );
                    equal( 1, $( '#testOutput canvas' ).length, "Canvas initialization/appending to container failed." );
                });
                
                test ( "getCanvas", function(){
                    ok( "function" == typeof( tinyC5.getCanvas ), "tinyC5 has no getCanvas function" );
                    var res = tinyC5.getCanvas();
                    ok( "object" == typeof( res ) );
                });
                
                test( "setFullscreen", function() {
                    ok( "function" == typeof( tinyC5.setFullscreen ), "tinyC5 has no setFullscreen function" );
                    var isFullscreen = tinyC5.isFullscreen();
                    tinyC5.setFullscreen( !isFullscreen );
                    equal( tinyC5.isFullscreen(), !isFullscreen, "setFullscreen does not seem to work properly." );
                    tinyC5.setFullscreen( isFullscreen );
                });
                
                test( "isFullscreen", function(){
                    ok( "function" == typeof( tinyC5.isFullscreen ), "tinyC5 has no isFullscreen function" );
                    var res = tinyC5.isFullscreen();
                    ok ( "boolean" == typeof( res ), "isFullscreen does not return proper value." );
                }); 
                
                test( "setSmoothing", function() {
                    ok( "function" == typeof( tinyC5.setSmoothing ), "tinyC5 has no setSmoothing function" );
                    var isSmoothing = tinyC5.isSmoothing();
                    tinyC5.setSmoothing( !isSmoothing );
                    equal( tinyC5.isSmoothing(), !isSmoothing, "setSmoothing does not seem to work properly." );
                    tinyC5.setSmoothing( isSmoothing );
                });
                
                test( "isSmoothing", function(){
                    ok( "function" == typeof( tinyC5.isSmoothing ), "tinyC5 has no isSmoothing function" );
                    var res = tinyC5.isSmoothing();
                    ok ( "boolean" == typeof( res ), "isSmoothing does not return proper value." );
                }); 
                
                test( "setCaptureMouse", function() {
                    ok( "function" == typeof( tinyC5.setCaptureMouse ), "tinyC5 has no setCaptureMouse function" );
                    var isCaptureMouse = tinyC5.isCaptureMouse();
                    tinyC5.setCaptureMouse( !isCaptureMouse );
                    equal( tinyC5.isCaptureMouse(), !isCaptureMouse, "setCaptureMouse does not seem to work properly." );
                    tinyC5.setCaptureMouse( isCaptureMouse );
                });
                
                test( "isCaptureMouse", function(){
                    ok( "function" == typeof( tinyC5.isCaptureMouse ), "tinyC5 has no isCaptureMouse function" );
                    var res = tinyC5.isCaptureMouse();
                    ok ( "boolean" == typeof( res ), "isCaptureMouse does not return proper value." + typeof( res ) );
                });                 
                
                test( "getTime", function(){
                    ok( "function" == typeof( tinyC5.getTime ), "tinyC5 has no getTime function" );
                    var res = tinyC5.getTime();
                    ok( "number" == typeof( res), "getTime returns invalid value." );
                    ok( res > 0, "getTime returns incorrect value." );
                });
                
                test( "color", function(){
                    ok( "function" == typeof( tinyC5.color ), "tinyC5 has no color function" );
                    var res = tinyC5.color( 1, 2, 3, 4 );
                    ok( "object" == typeof( res ), "color returns invalid value." );
                    equal( 1, res.r, "color return incorrect red value." );
                    equal( 2, res.g, "color return incorrect green value." );
                    equal( 3, res.b, "color return incorrect blue value." );
                    equal( 4, res.a, "color return incorrect alpha value." );
                    res = tinyC5.color( 1,2,3 );
                    ok( "object" == typeof( res ), "color returns invalid value." );
                    equal( 255, res.a, "color return incorrect alpha value." );
                });
                
                test( "clamp", function(){
                    ok( "function" == typeof( tinyC5.clamp ), "tinyC5 has no clamp function" );
                    var res = tinyC5.clamp(200);
                    ok( "number" == typeof( res ), "clamp returns invalid value." );
                    equal( 200, res, "clamp returns incorrect value." );
                    res = tinyC5.clamp(-200);
                    ok( "number" == typeof( res ), "clamp returns invalid value." );
                    equal( 0, res, "clamp returns incorrect value." );
                    res = tinyC5.clamp(500);
                    ok( "number" == typeof( res ), "clamp returns invalid value." );
                    equal( 255, res, "clamp returns incorrect value." );
                });
                
                test( "copyPixels", function(){
                    ok( "function" == typeof( tinyC5.copyPixels ), "tinyC5 has no copyPixels function" );                                        
                    
                    var p = new Array( tinyC5.WIDTH * tinyC5.HEIGHT * 4 );
                    for( var i=0; i < p.length; i++ ) {
                        p[i] = Math.floor( Math.random()*256 );
                    }
                    
                    var res = tinyC5.copyPixels(p);
                    ok( res, "copyPixels function return false. True expected." );
                    
                    res = tinyC5.copyPixels( new Array( 1 ) );
                    ok( !res, "copyPixels function return false. True expected." );
                    
                    var allEqual = true;
                    for( var j=0; j < tinyC5.pixels.length; j++ ) {
                        if ( tinyC5.pixels[j] != p[j] ) {
                            allEqual = false;
                            break;
                        }                        
                    }
                    ok( allEqual, "copyPixels function does not seem to work properly" );
                });
                
                test( "isMobile", function() {
                    ok( "function" == typeof( tinyC5.isMobile ), "Function isMobile does not exist." );
                    var res = tinyC5.isMobile();
                    ok( "boolean" == typeof(res), "isMobile returns an invalid value." );
                });
                
                module( "TinyC5Utils" );
                
                test( "getImagedataFromImage", function() {
                    ok( "function" == typeof( TinyC5Utils.getImagedataFromImage ), "Function getImagedataFromImage does not exist." );
                    var res = TinyC5Utils.getImagedataFromImage();
                    ok( null == res, "getImagedataFromImage returns wrong value for failure case." );
                });
            });
        </script>

    </head>
    <body>
        <h1 id="qunit-header">QUnit example</h1>
        <h2 id="qunit-banner"></h2>
        <div id="qunit-testrunner-toolbar"></div>
        <h2 id="qunit-userAgent"></h2>
        <ol id="qunit-tests"></ol>
        <div id="qunit-fixture">test markup, will be hidden</div>
        
        <!-- TinyC5 container will be hidden -->
        <div id="testOutput" style="display:none"></div>
    </body>
</html>